<?

if ($DATA['component']['id']) {
	
	$_plugin = 'Form Ajax';
	$_table = 'data';				// where info is stored

	$_record = array('id_data' => D_MB_SETTINGS, 'id_parent' => $DATA['component']['id'], 'assoc' => '');

	$_lang_indep = array('source' => '', 'credentials_letter' => '', 'credentials_subject' => '', 'from' => 'Site Engine <sb@rulezz.com.ua>');
	$_lang_dep	= array('caption');	// which fields are stored in language variations
	
	$_lang_dep_def = array(
		'en' => array(
			'caption'		=> '',
		),
		'ru' => array(
			'caption'		=> '',
		),
		'ua' => array(
			'caption'		=> '',
		)
	);

	
	$_crit = "id_data=".D_MULTIBLOCK." AND value='$_plugin' AND ".dbAndL('attr', COM_ENABLED);

	$DATA['objects'] = datafetch_array('db_list', array('table' => tb($_table), 'where' => $_crit, 'index' => 'id' )); // fetch data sources

	switch (action(array('editor_save'))) {
	
		case 'editor_save':

			$temp = array();
			
			foreach($_lang_indep as $k => $v)
				if (($t = trim(postdata($k))) !== '')
					$temp[] = array_merge($_record, array('name' => $k, 'value' => $t));
					
			foreach($DATA['langs'] as $lang)
				foreach($_lang_dep as $k)
					if (isset($_POST[$k][$lang['text']]) && (($t = trim($_POST[$k][$lang['text']])) !== ''))
						$temp[] = array_merge($_record, array('name' => $k, 'value' => $t, 'assoc' => $lang['text']));	// language dependent data

			dataset('db_delete', tb('data'), "(id_data=".D_MB_SETTINGS.") AND (id_parent={$DATA[component][id]})");
			dataset('db_insert', tb('data'), $temp);
			
			return true;	// end of component edition
	}
	

	$DATA['settings'] = array('data' => $_lang_dep_def);	// load defaults

	$temp = datafetch_array('db_list', array(
		'table' => tb('data'), 
		'where' => "(id_data=".D_MB_SETTINGS.") AND (id_parent={$DATA[component][id]}) AND (assoc='')", 
		'index' => 'name' ));

	foreach($_lang_indep as $k => $v)
		$DATA['settings'][$k] = isset($temp[$k]) ? $temp[$k]['value'] : $v;	// load language independent data

	$temp = datafetch_array('db_list', array('table' => tb('data'), 'where' => "(id_data=".D_MB_SETTINGS.") AND (id_parent={$DATA[component][id]}) AND (assoc!='')"));
	
	foreach($temp as $k => $v)	
		$DATA['settings']['data'][$v['assoc']][$v['name']] = $v['value'];	// load language dependent data
		
	return false;

} else exit;